<?php

namespace App\Http\Controllers;

use App\Models\Group;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Inertia\Inertia;
use App\Models\Room;

class RoomController extends Controller
{
    public function index()
    {
        $group = Group::all();
        return Inertia::render('Booking/Room',[
            'rooms' => Room::all(),
            'groups' => $group
        ]);
    }

    public function update(Request $request): \Illuminate\Http\RedirectResponse
    {
        $data = $request->all();
        $id = $data['id'];
        Room::dataSave($data, $id);

        return Redirect::route('rooms');
    }

    public function delete(Request $request): \Illuminate\Http\RedirectResponse
    {
        $id = $request->get('id');
        Room::query()->find($id)->delete();

        return Redirect::route('rooms');
    }

    public function group(Request $request): \Illuminate\Http\RedirectResponse
    {
        $name = $request->get('name');
        Group::create(['name'=>$name]);

        return Redirect::route('rooms');
    }

    public function removeGroup(Request $request): \Illuminate\Http\RedirectResponse
    {
        $id = $request->get('id');
        Group::query()->find($id)->delete();

        return Redirect::route('rooms');
    }



}
